package com.google.code.stalkernet.advertisement;

/**
 * Abstract base class for implementations of {@link Advertisement} interface.
 *
 * @author Mikhail Vladimirov
 */
public abstract class AbstractAdvertisement implements Advertisement
{
    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode ()
    {
        return getSocketAddress ().hashCode () * 17 + getNodeID ().hashCode ();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals (Object obj)
    {
        if (obj instanceof Advertisement)
        {
            Advertisement o = (Advertisement)obj;

            return getSocketAddress ().equals (o.getSocketAddress ()) &&
                getNodeID ().equals (o.getNodeID ());
        }
        else return false;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString ()
    {
        return AdvertisementUtils.formatAdvertisement (this);
    }
}
